<template>
	<div>
		<textarea name="editor" :id="id"></textarea>
	</div>
</template>

<script>
	
	export default {
		props: {
			'content': String,
		},

		data() {
			return {
				ckedite: null,
				id: parseInt(Math.random() * 10000).toString(),
			}
		},
		mounted() {
			const self = this;
			self.ckedite = window.CKEDITOR.replace('editor', {
				filebrowserImageUploadUrl: process.env.VUE_APP_BASE_API + '/upload/ckeditimage?domain=' + process.env.VUE_APP_BASE_API,
				removePlugins: 'easyimage,cloudservices',
				removeDialogTabs: 'image:advanced;image:Link',
			});
			self.ckedite.on('fileUploadRequest', function(e) {
				var xhr = e.data.fileLoader.xhr;
				xhr.withCredentials = true;
			});
			self.ckedite.setData(self.content);

			// if(this.isView == true){
			// 	console.log("self.ckedite.readOnly: " + self.ckedite.readOnly);
			// 	this.ckedite.setReadOnly( true )
			// }
			self.ckedite.on('blur', function() {
				self.$emit('update:content', self.ckedite.getData())
			})
		},
	}
</script>

<style>
</style>
